package com.ypj.rpc.registry;

import com.alibaba.nacos.api.exception.NacosException;
import com.ypj.rpc.enumeration.RpcError;
import com.ypj.rpc.exception.RpcException;
import com.ypj.rpc.utils.NacosUtils;
import lombok.extern.slf4j.Slf4j;

import java.net.InetSocketAddress;

/**
 * 服务注册中心
 */
@Slf4j
public class NacosServiceRegistry implements ServiceRegistry {

    @Override
    public void register(String serviceName, InetSocketAddress inetSocketAddress) {
        try {
            NacosUtils.registerService(serviceName,inetSocketAddress);
        } catch (NacosException e) {
            log.error("注册服务时发生错误：",e);
            throw new RpcException(RpcError.REGISTER_SERVICE_FAILED.getMessage());
        }
    }
}
